package main

import (
	"context"
	"fmt"
	"yunion.io/x/jsonutils"
	"yunion.io/x/onecloud/pkg/mcclient"
	modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
)

func main() {
	client := mcclient.NewClient("https://api.saltyun.com/api/s/identity/v3", // 注意此地址不带端口
		60,
		true,
		true,
		"",
		"")
	token, err := client.Authenticate("sysadmin", "N48XSRmcsP5YMcPf", "Default", "system", "Default")
	if err != nil {
		panic(err)
	}

	fmt.Println("token:", token)

	s := client.NewSession(context.Background(),
		"region0",
		"",
		"apigateway", // 注意此endpoint类型
		token,
	)

	//result, err := modules.Servers.List(s, nil)

	result, err := modules.Hosts.List(s, nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s", jsonutils.Marshal(result).PrettyString())
}
